const webpack = require('webpack');
const {merge} = require('webpack-merge');
const baseConfig = require('./webpack.base.config');

module.exports = merge(baseConfig, {

    plugins: [
        new webpack.DefinePlugin({
            SERVICE_URL: JSON.stringify('/api')
        })
    ],

    // 模式
    mode: 'development',

    // sourceMap
    devtool:'cheap-module-source-map',


    // 自动开启服务
    devServer: {
        host: '127.0.0.1',
        port: '8090',
        open: true,
        // 开发中，允许前端路由使用 history 模式
        historyApiFallback: true,

        proxy: {
            // 默认替换方式：/api/admin  -> http://127.0.0.1:8088/api/admin
            // '/api': 'http://127.0.0.1:8088'

          
            '/api': {
                target: 'http://127.0.0.1:8088',

                // /api/admin  -> http://127.0.0.1:8088/admin  去掉 /api
                pathRewrite: { '^/api': ''},

                // 默认值请求中 Host  http://shirly.com
                // 设置为 true  请求头 Host http://127.0.0.1:8088
                changeOrigin: true,
            }

        }
    }
})